package com.jprocms.module.cms.controller.admin.imgblock;

import com.jprocms.module.cms.util.CmsContextUtil;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.jpro.framework.common.pojo.PageParam;
import com.jpro.framework.common.pojo.PageResult;
import com.jpro.framework.common.pojo.CommonResult;
import com.jpro.framework.common.util.object.BeanUtils;
import static com.jpro.framework.common.pojo.CommonResult.success;

import com.jpro.framework.excel.core.util.ExcelUtils;

import com.jpro.framework.apilog.core.annotation.ApiAccessLog;
import static com.jpro.framework.apilog.core.enums.OperateTypeEnum.*;

import com.jprocms.module.cms.controller.admin.imgblock.vo.*;
import com.jprocms.module.cms.dal.dataobject.imgblock.ImgblockDO;
import com.jprocms.module.cms.service.imgblock.ImgblockService;

@Tag(name = "管理后台 - 飘窗板块")
@RestController
@RequestMapping("/cms/imgblock")
@Validated
public class ImgblockController {

    @Resource
    private ImgblockService imgblockService;

    @PostMapping("/create")
    @Operation(summary = "创建飘窗板块")
    @PreAuthorize("@ss.hasPermission('cms:imgblock:create')")
    public CommonResult<Long> createImgblock(@Valid @RequestBody ImgblockSaveReqVO createReqVO) {
        createReqVO.setSiteId(CmsContextUtil.getCurrSiteId());
        return success(imgblockService.createImgblock(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新飘窗板块")
    @PreAuthorize("@ss.hasPermission('cms:imgblock:update')")
    public CommonResult<Boolean> updateImgblock(@Valid @RequestBody ImgblockSaveReqVO updateReqVO) {
        imgblockService.updateImgblock(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除飘窗板块")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('cms:imgblock:delete')")
    public CommonResult<Boolean> deleteImgblock(@RequestParam("id") Long id) {
        imgblockService.deleteImgblock(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得飘窗板块")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('cms:imgblock:query')")
    public CommonResult<ImgblockRespVO> getImgblock(@RequestParam("id") Long id) {
        ImgblockDO imgblock = imgblockService.getImgblock(id);
        return success(BeanUtils.toBean(imgblock, ImgblockRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得飘窗板块分页")
    @PreAuthorize("@ss.hasPermission('cms:imgblock:query')")
    public CommonResult<PageResult<ImgblockRespVO>> getImgblockPage(@Valid ImgblockPageReqVO pageReqVO) {
        pageReqVO.setSiteId(CmsContextUtil.getCurrSiteId());
        PageResult<ImgblockDO> pageResult = imgblockService.getImgblockPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ImgblockRespVO.class));
    }

}